import _ from "lodash";
// 引入深拷贝
// 用 store.js操作
import LS from "store";
import { UPDATE_ALl_AUTHORITY_TYPE, CLEAR_ALl_AUTHORITY_TYPE } from "./types";
const initState = {
    adminname: "",
    token: "",
    role: -1,
    checkedkeys: [],
};
const reducer = (state = LS.get("userinfo", {...initState }), action = {}) => {
    let newState = _.cloneDeep(state);
    const { type, ...payload } = action;
    switch (type) {
        case UPDATE_ALl_AUTHORITY_TYPE:
            // newState = payload.data;或者
            Object.assign(newState, payload.data);
            break;
        case CLEAR_ALl_AUTHORITY_TYPE:
            // newState = payload.data;或者
            Object.assign(newState, initState);
            break;
        default:
            break;
    }
    return newState;
};

export default reducer;